package com.jieyang.oa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jieyang.oa.dao.ExpenseDao;
import com.jieyang.oa.pojo.Vo.AuditVo;
import com.jieyang.oa.pojo.entity.Duty;
import com.jieyang.oa.pojo.entity.Expense;
import com.jieyang.oa.service.ExpenseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 29276
 * @version 1.0
 * @description: TODO
 * @date 2021/8/21 14:14
 */
@Service
@Transactional
public class ExpenseServiceImpl implements ExpenseService {

    @Resource
    private ExpenseDao expenseDao;

    @Override
    public Integer insert(Expense expense) {
        return expenseDao.insert(expense);
    }

    @Override
    public List<AuditVo> selectByAudit(String nextAuditor) {
        return expenseDao.selectByAudit(nextAuditor);
    }

    @Override
    public PageInfo<Expense> selectByEmpId(String empId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);

        List<Expense> duties = expenseDao.selectByEmpId(empId);

        PageInfo<Expense> dutyPageInfo = new PageInfo<>(duties);
        int ceil = (int) Math.ceil((expenseDao.count(empId)*1.0)/pageSize);
        dutyPageInfo.setPages(ceil);
        dutyPageInfo.setSize(expenseDao.count(empId));
        return dutyPageInfo;

    }
}
